package com.lookme.lmtool.cracker.filter.warping;

import com.jhlabs.image.PerspectiveFilter;
import com.lookme.lmtool.cracker.CrackerConstants;
import com.lookme.lmtool.cracker.annotation.FilterAnnotation;
import com.lookme.lmtool.cracker.annotation.ParamAnnotation;
import com.lookme.lmtool.cracker.filter.AbstractFilter;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;

@FilterAnnotation(groupName = CrackerConstants.FILTER_GROUP_NAME_WARPING,name="透视变形")
public class FilterPerspective extends AbstractFilter {

    @XStreamAsAttribute
    @ParamAnnotation(name = "左上角X偏移坐标", desc = "左上角X偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=0,max=10000)
    int x0=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "左上角Y偏移坐标", desc = "左上角Y偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=0,max=10000)
    int y0=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "右上角X偏移坐标", desc = "右上角X偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=-10000,max=0)
    int x1=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "右上角Y偏移坐标", desc = "右上角Y偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=0,max=10000)
    int y1=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "右下角X偏移坐标", desc = "右下角X偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=-10000,max=0)
    int x2=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "右下角Y偏移坐标", desc = "右下角Y偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=-10000,max=0)
    int y2=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "左下角X偏移坐标", desc = "左下角X偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=0,max=10000)
    int x3=0;
    @XStreamAsAttribute
    @ParamAnnotation(name = "左下角Y偏移坐标", desc = "左下角Y偏移坐标",inputType = ParamAnnotation.InputType.Spinner,min=-10000,max=0)
    int y3=0;

    @ParamAnnotation(name = "是否裁剪", desc = "是否裁剪",inputType = ParamAnnotation.InputType.Radio,width = 45)
    boolean clip=false;
    @Override
    public BufferedImageOp getFilter() {
        return null;
    }

    @Override
    public BufferedImage filter(BufferedImage src, BufferedImage dst) {
        PerspectiveFilter filter= new PerspectiveFilter();
        filter.setClip(clip);
        filter.setCorners(x0, y0, src.getWidth()+ x1,y1, src.getWidth()+ x2,src.getHeight()+ y2,  x3,src.getHeight()+ y3);
            return filter.filter(src, dst);
    }
}
